package cn.kgc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author wangyue
 * @version 1.0
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsWebFilter(){
        //跨域配置信息
        CorsConfiguration corsConfiguration=new CorsConfiguration();
        //允许跨域访问的域名
        corsConfiguration.addAllowedOriginPattern("*");
        //允许跨域访问的请求方式
        corsConfiguration.addAllowedMethod("*");
        //允许跨域访问的请求头
        corsConfiguration.addAllowedHeader("*");
        //允许设置cookie信息
        corsConfiguration.setAllowCredentials(true);
        //允许跨域访问的路径
        UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",corsConfiguration);
        //返回跨域过滤器
        return new CorsWebFilter(source);
    }
}